package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.grandchild.GrandChildMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.GrandChildPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GET_GRAND_CHILD_RANK_DETAIL_INFO, desc = "获取孙子排行孙子详细信息")
public class GrandChildRankDetailInfoCmd extends AbstractCommand {
    GrandChildProto.GrandChildRankDetailInfoReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = GrandChildProto.GrandChildRankDetailInfoReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (reqMsg.getServerId() == GameServer.getInstance().getServerId()) {//本服
            GrandChildData grandChildData = GrandChildMgr.getGrandChildData(reqMsg.getUserId(), reqMsg.getId());
            GrandChildProto.GrandChildRankDetailInfoRespMsg.Builder respMsg = GrandChildProto.GrandChildRankDetailInfoRespMsg.newBuilder();
            if(null == grandChildData){
                respMsg.setRet(GameErrorCode.E_GRAND_CHILD_NO_EXIST);
            }else {
                respMsg.setRet(0);
                respMsg.setGrandChild(GrandChildPb.parseGrandChildMsg(grandChildData));
            }
            player.sendPacket(ClientProtocol.U_GET_GRAND_CHILD_RANK_DETAIL_INFO, respMsg);
        } else {//跨服
            YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_GET_GRAND_CHILD_RANK_DETAIL_INFO, reqMsg.toBuilder());
            GamePlayerMgr.sendPacket(player, message);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
